<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="show ? rowObj.T1 : rowObj.F1" :xs="show ? rowObj.T2 : rowObj.F2">
        <workSiteLeft ref="workSiteLeft" :show="show" @showLeft="showLeft" @queryVal="queryVal" />
      </el-col>
      <el-col :span="show ? rowObj.T3 : rowObj.F3" :xs="show ? rowObj.T4 : rowObj.F4">
        <div class="container-body">
          <el-form :inline="true" :model="queryParams" size="mini">
            <el-col :span="23">
              <el-button style="margin-right: 6px" size="mini" :icon="show ? 'el-icon-s-fold' : 'el-icon-s-unfold'" circle
                @click="showLeft(show)"></el-button>
              <el-form-item label="拌合楼">
                <el-select style="width: 130px" v-model="queryParams.stationCode" clearable size="mini"
                  placeholder="请选择拌合楼">
                  <el-option v-for="item in cementListData" :key="item.id" :label="item.name"
                    :value="item.code"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="用料项目">
                <el-select style="width: 120px" size="mini" v-model="queryParams.projectId" placeholder="请选择" filterable
                  clearable :popper-append-to-body="false">
                  <el-option v-for="item in projectIdList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="级配类型">
                <el-select style="width: 120px" v-model="queryParams.matchType" clearable size="mini"
                  placeholder="请选择级配类型">
                  <el-option v-for="item in matchTypeList" :key="item.id" :label="item.type"
                    :value="item.type"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="配方编号">
                <el-select style="width: 120px" v-model="queryParams.matchCode" clearable size="mini" placeholder="请选择">
                  <el-option v-for="item in matchCodeList" :key="item.value" :label="item.label"
                    :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <!-- v-if="$hasPermission('api:asphaltMatch:list')" -->
                <el-button icon="el-icon-search" type="primary" @click="handleQuery()">查询</el-button>
              </el-form-item>
            </el-col>
          </el-form>

          <el-table :data="dataList" v-loading="loading" fit border size="mini" highlight-current-row stripe>
            <el-table-column prop="projectName" label="用料项目" align="center" min-width="120px"></el-table-column>
            <el-table-column prop="stationName" label="拌合楼" align="center" min-width="120px"></el-table-column>
            <el-table-column prop="matchType" label="级配类型" align="center" min-width="120px"></el-table-column>
            <el-table-column prop="matchName" label="配方名称" align="center" min-width="120px"></el-table-column>
            <el-table-column prop="matchCode" label="配方编号" align="center" min-width="120px"></el-table-column>
            <el-table-column prop="hotConfig" label="热料筛分级配" align="center" min-width="160px">
              <template slot-scope="scope">
                <el-link type="primary" @click="showEditHot(scope.row)">修改筛分级配</el-link>
                <span v-if="1 == scope.row.hotConfig">（已配置）</span>
                <span v-else>（未配置）</span>
              </template>
            </el-table-column>
            <el-table-column prop="coldConfig" label="冷料配比" align="center" min-width="160px">
              <template slot-scope="scope">
                <el-link type="primary" @click="showEditCold(scope.row)">材料配合比</el-link>
                <span v-if="1 == scope.row.coldConfig">（已配置）</span>
                <span v-else>（未配置）</span>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="siteCenter" label="现场中心" align="center" min-width="120px"></el-table-column> -->
            <el-table-column prop="pavingLevelName" label="摊铺层级" align="center" min-width="120px"></el-table-column>
          </el-table>
          <pagination class="fenye" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>
        <EditHot ref="editHot" @success="handleQuery()"></EditHot>
        <EditCold ref="editCold" @success="handleQuery()"></EditCold>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import EditHot from './edit-hot.vue'
import EditCold from './edit-cold.vue'
import {
  sysStationList,
  asphaltMatch,
  materielProject,
  getInitMatchCode,
  asphaltMatchName,
  getHotList,
  saveHot,
  getCold,
  saveCold,
  getMatchCode,
} from "@/api/bitumenMixingStation/matchingManage/screenTest";
import workSiteLeft from "@/views/components/workSiteLeft";

import {
  asphaltMatchTypeList,
} from "@/api/bitumenMixingStation/producedData/monitor";

export default {
  name: "screenTest",
  data() {
    return {
      show: true,
      rowObj: {
        T1: 3,
        T2: 24,
        T3: 21,
        T4: 24,
        F1: 0,
        F2: 0,
        F3: 24,
        F4: 24,
      },
      submitting: true,
      visible: false,
      isAdd: true,
      dataList: [],
      loading: false,//表格加载
      loadingForm: false,//新增修改加载
      cementListData: [],//拌合楼下拉列表
      matchTypeList: [],//级配类型
      matchCodeList: [],
      projectIdList: [],
      matchNameList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,

      form: {},
    };
  },
  components: {
    EditHot,
    EditCold,
    workSiteLeft
  },
  filters: {
    /**
     * 显示骨料或粉料信息
     */
    showGravelAndPowder(val) {
      let property = val.column.property;
      let data = val.row;

      let value = data[property];
      if (!!value) {
        let name = !!data[property + 'Name'] ? data[property + 'Name'] + '：' : '';
        return name + value;
      }
      return '/';
    },

    /**
     * 显示数字
     */
    showNumber(val) {
      if (!!val) {
        return val;
      }
      return '/';
    },

    /**
     * 显示温度范围
     */
    showTemperature(val) {
      let min = !!val.temperatureMin ? val.temperatureMin : '/';
      let max = !!val.temperatureMax ? val.temperatureMax : '/';
      if (min == max) {
        return min;
      }
      return min + '~' + max;
    }
  },

  created() {
    this.getCementList();
    this.getAsphaltMatchTypeList()
    this.getInitMatchCodeData()
    this.getMaterielProject()
    this.getAsphaltMatchName()
    this.getList();
  },
  methods: {
    showLeft(show) {
      this.show = !show;
    },
    queryVal(val) {
      this.queryParams.id = val.id;
      this.handleQuery();
    },
    getList() {
      this.loading = true;
      asphaltMatch(this.queryParams).then((res) => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    getSearchParams() {
      const params = {};
      for (const key in this.queryParams) {
        if (key === "time") {
          const time = this.queryParams[key];
          if (time && time.length === 2) {
            params.startTime = time[0];
            params.endTime = time[1];
          }
        } else {
          params[key] = this.queryParams[key];
        }
      }
      return params;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams = this.getSearchParams();
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 用料项目
    getMaterielProject() {
      materielProject().then((res) => {
        this.projectIdList = res.rows
      })
    },
    // 配方编号
    getInitMatchCodeData() {
      getInitMatchCode().then((res) => {
        this.matchCodeList = res.data
      })
    },
    // 查询拌合楼下拉列表
    getCementList() {
      sysStationList({
        type: 'asphalt'
      }).then((res) => {
        this.cementListData = res.data || [];
      });
    },
    // 级配类型
    getAsphaltMatchTypeList() {
      asphaltMatchTypeList().then((res) => {
        this.matchTypeList = res.data;
      });
    },

    getAsphaltMatchName() {
      asphaltMatchName().then((res) => {
        this.matchNameList = res.data
      })
    },
    // 删除
    onDelete(id) {
      this.$confirm("此操作将删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          cementMatchRemove(id).then((res) => {
            this.getList();
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    /**
 * 关闭弹窗
 */
    doClose() {
      this.visible = false;

    },
    /**
 * 提交表单
 */
    doSubmit() {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          if (this.isAdd) {
            // 新增
            // this.form.stationCode = "111";
            asphaltMatchAdd(this.form).then((res) => {
              this.$message.success("新增设计生产配比成功！");
              this.getList();
              this.visible = false;
              // this.btnLoading = false;
              // this.open = false;
            })

          } else {
            // 修改
            asphaltMatchEdit(this.form).then((res) => {
              this.$message.success("修改设计生产配比成功！");
              this.getList();
              this.visible = false;
              // this.open = false;
            })
          }
        }
      });
    },
    /**
 * 显示修改筛分级配弹窗界面
 */
    showEditHot(obj) {
      this.$refs.editHot.init(obj)
    },
    /**
     * 显示修改冷料配比
     */
    showEditCold(obj) {
      this.$refs.editCold.init(obj)
    }

  },
};
</script>
<style scoped>
.myForm>>>.el-input-number {
  width: 100%;
}

.myForm>>>.el-input__inner {
  text-align: left;
}

.myForm>>>.el-input-number {
  width: 100%;
}

.myForm>>>.el-input__inner {
  text-align: left;
}

.form-item-out {
  margin-bottom: 0px;
}

.colSplit {
  text-align: center;
  font-size: 16px;
}

.el-col {
  border: 1px solid transparent;
}
</style>





